//
//  BN_Mine_TeacherData.m
//  BabyNow
//
//  Created by 刘泽琛 on 14-5-23.
//  Copyright (c) 2014年 iMobile. All rights reserved.
//

#import "BN_Mine_TeacherData.h"

@implementation BN_Mine_TeacherData

- (id)init {
    if (self = [super init]) {
        self.sectionArr = @[@"发勋章、写评语",@"颁发勋章",@"老师周评"];
    }
    return self;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSInteger rowOfSection = 0;
    switch (section) {
        case 0:
            rowOfSection = 1;
            break;
        case 1:
            rowOfSection = 2;
            break;
        default:
            break;
    }
    return rowOfSection;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 20;
}

-(void)setExtraCellLineHidden:(UITableView *)tableView
{
    UIView *view = [UIView new];
    view.backgroundColor = APP_OBJECT_GRAY_COLOR;
    [tableView setBackgroundColor:[UIColor clearColor]];
    [tableView setTableFooterView:view];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"BN_Mine_TeacherData";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    [self setExtraCellLineHidden:tableView];
    
    switch (indexPath.section) {
        case 0:
            cell.textLabel.text = self.sectionArr[0];
            cell.imageView.image = [UIImage imageNamed:@"babymedal"];
            break;
        case 1:
            cell.textLabel.text = self.sectionArr[indexPath.row+1];
            break;
        default:
            break;
    }
    
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0 && indexPath.section == 0) {
        // 打开发勋章、写评语
        BN_UserInfo *userInfo = [BN_UserHelper unArchiverAccountInfo];
        NSInteger userType = [userInfo.userType integerValue];
        switch (userType) {
            case ENUM_ROLE_LEADER:
                [[NSNotificationCenter defaultCenter]postNotificationName:@"K_WAIT" object:nil];
                break;
            default:
                [[NSNotificationCenter defaultCenter]postNotificationName:KMINI_PUSH_MEDAL_COMMENT object:nil];
                break;
        }
    }else {
        [[NSNotificationCenter defaultCenter]postNotificationName:@"K_WAIT" object:nil];
    }
}

#pragma mark
#pragma mark 资源
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:KMINI_PUSH_MEDAL_COMMENT object:nil];
    
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"K_WAIT" object:nil];
}
@end
